<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/base/taglibs.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>${systemOption.systemTitle}</title>
    <%@ include file="/base/head.jsp"%>
    <script type="text/javascript" charset="UTF-8">
   $(document).ready(function(){
	//获取年度下拉框值
        var date = new Date(); 
        var year = date.getFullYear() - 2;
        for(var i = 0;i < 5 ; i++){
           if(year + i == date.getFullYear()){
             var option= $("<option></option>").val(year+i).text(year+i).attr("selected",true).appendTo($("#year"));
           }else{
             $("<option></option>").val(year+i).text(year+i).appendTo($("#year"));
           }
       	}
    });
    
   function getDate(){	
	var year=document.getElementById("year").value;	
	var year2=document.getElementById("year2");	
	year2.value=year;	
	var month=document.getElementById("month").value;	
	var month2=document.getElementById("month2");	
	month2.value=month;	
}
	//生成
	function add(){
		var year= $('#year').val();
		var month= $('#month').val();
		$.ajax({url:'${ctx}/salary/addSalary.action',
		data:{year:year,month:month},
		success:function(data){
			console.log(data);
			if(data == "01"){
				$.messager.alert('友情提示','当前月份的工资信息生成成功','info');
			}else if(data == "02"){
				$.messager.alert('错误提示','当前月份的工资信息生成失败','error');
			}else if(data == "03"){
				$.messager.alert('错误提示','当前月份的工资信息已生成','error');
			}
			resetDG('#baseList');
		}
		});
	}
	
	//修改
  function edit(){
  	var row = $('#baseList').datagrid('getSelected');
	if (!row){
		$.messager.alert('友情提示','请选择信息','error');
	}else{
		$('#updateWnd').show();
		$('#updateWnd').dialog({
        iconCls:'icon-edit',
        title:'修改信息',
        modal:true,
        buttons:[{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					$('#updateFrom').form('submit',{
					    success: function(data){
					        if(data=='01'){
					            $.messager.alert('友情提示','修改成功','info');
					            resetDG('#baseList');
					        }else{
					        	$.messager.alert('友情提示','修改失败','error');
					        }
					        $('#updateWnd').dialog('close');
					    }
					});
				}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					$('#updateWnd').dialog('close');
				}
		}]
            });
        console.log(row);
      // $('#updateFrom').form('reset');
        $('#baseName2').textbox('setValue',row.struename);
 		 $('#baseId2').val(row.sid);
 		$('#baseuId2').val(row.uid);
 		$('#baseEmpid2').textbox('setValue',row.sempid);
 		$('#baseYear2').textbox('setValue',row.syear);
 		$('#baseMonth2').textbox('setValue',row.smonth);
 		$('#baseBasesalary2').textbox('setValue',row.sbasesalary);
 		$('#baseFinalsalary2').textbox('setValue',row.sfinalsalary);
 		$('#baseLatecomee2').val(row.slatecome);
 		$('#baseEarlyleave2').val(row.searlyleave);
 		$('#baseLeave2').val(row.sleave);
 		$('#baseOvertime2').val(row.sovertime);
 		$('#baseNegletwork2').val(row.snegletwork);
 		$('#baseOld2').val(row.sold);
 		$('#baseUnemployment2').val(row.sunemployment);
 		$('#baseInjury2').val(row.sinjury);
 		$('#baseBear2').val(row.sbear);
 		$('#baseMedical').val(row.sleave);
 		$('#baseHous2').val(row.shouse);
 		$('#baseRemarkl2').val(row.remark); 
		}
	}


	function export1(){
	var year=$('#year').val();
  	var month=$('#month').val();
	location.href= "${ctx}/salary/export.action?year="+year+"&month="+month;
	}
 //分页查询
  function doQuery(){
  	var queryParams=$('#baseList').datagrid('options').queryParams;
  	queryParams.nameSch=$('#nameSch').val();
  	queryParams.empIdSch=$('#empIdSch').val();
  	queryParams.year=$('#year').val();
  	queryParams.month=$('#month').val();
  	
  	//重置当前页数为1
  	resetDG('#baseList');

  } 
  
  
  function formatSal(val,row){
  return parseFloat(val).toFixed(2);
	}
  
    </script>  
        
  </head>
  
  <body>
 
<!-- 主窗口 -->  	 
    <table id="baseList" class="easyui-datagrid" data-options="fit:true,
    								rownumbers:true,
									singleSelect:true,
									striped:true,
									toolbar:'#tb',
									pagination:true,
									pageSize:20,
									pageList:[20,30,50,100],
									url:'${ctx}/salary/listSalary.action'">
		 <thead data-options="frozen:true">
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'uid',hidden:true"></th>
				<th data-options="field:'sempid',align:'center'" width="150px"><strong>工号</strong></th>
				<th data-options="field:'struename',align:'center'" width="100px"><strong>姓名</strong></th>
				<th data-options="field:'syear',align:'center'" width="100px"><strong>年份</strong></th>
				<th data-options="field:'smonth',align:'center'" width="100px"><strong>月份</strong></th>
			</tr>
			</thead>
		<thead>
           <tr>
				<th data-options="field:'sbasesalary',align:'center',formatter:formatSal" width="100px"><strong>基本工资</strong></th>
				<th data-options="field:'sfinalsalary',align:'center',formatter:formatSal" width="100px"><strong>实发工资</strong></th>
				<th data-options="field:'slatecome',align:'center',formatter:formatSal" width="100px"><strong>迟到罚款</strong></th>
				<th data-options="field:'searlyleave',align:'center',formatter:formatSal" width="100px"><strong>早退罚款</strong></th>
				<th data-options="field:'sleave',align:'center',formatter:formatSal" width="100px"><strong>请假罚款</strong></th>
				<th data-options="field:'sovertime',align:'center',formatter:formatSal" width="100px"><strong>加班奖金</strong></th>
				<th data-options="field:'snegletwork',align:'center',formatter:formatSal" width="100px"><strong>旷工罚金</strong></th>
				<th data-options="field:'sold',align:'center',formatter:formatSal" width="100px"><strong>养老保险</strong></th>
				<th data-options="field:'sunemployment',align:'center',formatter:formatSal" width="100px"><strong>失业保险</strong></th>
				<th data-options="field:'sinjury',align:'center',formatter:formatSal" width="100px"><strong>工伤保险</strong></th>
				<th data-options="field:'sbear',align:'center',formatter:formatSal" width="100px"><strong>生育保险</strong></th>
				<th data-options="field:'smedical',align:'center',formatter:formatSal" width="100px"><strong>医疗保险</strong></th>
				<th data-options="field:'shouse',align:'center',formatter:formatSal" width="100px"><strong>公积金 </strong></th>
				<th data-options="field:'remark',align:'center'," width="300px"><strong>备注</strong></th>
			</tr>
		</thead>
		
	</table>
<!-- Datagrid工具栏 -->
<div id="tb">
	<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
	   <td class="toolDiv">  	
	   <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-database-add',plain:true" onclick="add()">生成</a><span class="vline">|</span>	
	   <a href="javascript:void(0)" onclick="edit()" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a><span class="vline">|</span>	
	   <a href="javascript:void(0)" onclick="export1()" class="easyui-linkbutton" data-options="iconCls:'icon-printer',plain:true" >导出</a>
		</td>
	</tr>
	<tr>
	   <td class="serchDiv">
			&nbsp;&nbsp;员工名称：<input id="nameSch"  class="easyui-textbox" type="text">
			&nbsp;&nbsp;员工工号：<input id="empIdSch"   class="easyui-textbox" type="text">
			&nbsp;&nbsp;年份：<select id="year" name="attendence.year" ></select>
			&nbsp;&nbsp;月份：	<select id="month" name="month">
				<c:forEach var="everyMonth" items="${monthList}"> 
	           		 <c:choose>
	           			  	<c:when test="${everyMonth==month}">
	           			  		<option  value="${everyMonth}" selected>${everyMonth}</option>
	           			  	</c:when>
	           			  	<c:otherwise>
	           			  		<option value="${everyMonth}">${everyMonth}</option>
	           			  	</c:otherwise>
	           			  </c:choose>
				</c:forEach>
			</select>
			&nbsp;&nbsp;<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doQuery()">查询</a>
			&nbsp;&nbsp;
			
		</td>
	</tr>
	</table>
</div>

<!--修改窗口-->
    <div id="updateWnd"  style="width: 600px; height: 400px; padding: 5px; background: #fafafa;display: none">
    	<form id="updateFrom" method="post" action="${ctx }/salary/updateSalary.action">
    			<input id="baseId2" name="id" type="hidden"/>
    			<input id="baseuId2" name="uid" type="hidden"/>
                <table cellpadding=3>
                	<tr>
                        <td>姓名</td>
                        <td><input id="baseName2" name="struename" class="easyui-textbox"  data-options="required:true" readonly="readonly" style="width:200px"/></td>
                        <td>工号</td>
                        <td><input id="baseEmpid2" name="sempid" class="easyui-textbox"  data-options="required:true" readonly="readonly" style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>年份</td>
                        <td><input id="baseYear2" name="syear" class="easyui-textbox"  data-options="required:true" readonly="readonly" style="width:200px"/></td>
                        <td>月份</td>
                        <td><input id="baseMonth2" name="smonth" class="easyui-textbox"  data-options="required:true" readonly="readonly" style="width:200px"/></td>
                    </tr>
                     <tr>
                        <td>基本工资</td>
                        <td><input id="baseBasesalary2" name="sbasesalary" class="easyui-textbox"  data-options="required:true" style="width:200px"/></td>
                        <td>实发工资</td>
                        <td><input id="baseFinalsalary2" name="sfinalsalary" class="easyui-textbox"  data-options="required:true"  style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>早退罚款</td>
                        <td><input id="baseLatecomee2" name="slatecome" data-options="required:true" style="width:200px"/></td>
                        <td>请假罚款</td>
                        <td><input id="baseEarlyleave2" name="searlyleave"   data-options="required:true"  style="width:200px"/></td>
                    </tr>
                     <tr>
                        <td>请假罚款</td>
                        <td><input id="baseLeave2" name="sleave"   data-options="required:true" style="width:200px"/></td>
                        <td>加班奖金</td>
                        <td><input id="baseOvertime2" name="sovertime"   data-options="required:true"  style="width:200px"/></td>
                    </tr>
                     <tr>
                        <td>旷工罚金</td>
                        <td><input id="baseNegletwork2" name="snegletwork"   data-options="required:true" style="width:200px"/></td>
                        <td>养老保险</td>
                        <td><input id="baseOld2" name="sold"  data-options="required:true"  style="width:200px"/></td>
                    </tr>
                     <tr>
                        <td>失业保险</td>
                        <td><input id="baseUnemployment2" name="sunemployment"  data-options="required:true" style="width:200px"/></td>
                        <td>工伤保险</td>
                        <td><input id="baseInjury2" name="sinjury"  data-options="required:true"  style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>生育保险</td>
                        <td><input id="baseBear2" name="sbear"  data-options="required:true" style="width:200px"/></td>
                        <td>医疗保险</td>
                        <td><input id="baseMedical" name="sbear"   data-options="required:true"  style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>公积金</td>
                        <td><input id="baseHous2" name="shouse"  data-options="required:true" style="width:200px"/></td>
                        <td>备注</td>
                        <td><input id="baseRemarkl2" name="remark"  data-options="required:true"  style="width:200px"/></td>
                    </tr>
                </table>
        </form>
    </div> 

	<!-- 选择员工详情-->
	<div id="empWnd" style="display: none; width: 800px; height: 400px; border:false;">
	</div>
  </body>
  
  <script type="text/javascript">
  	//选择员工信息
    function chooseEmp()
    {
		var empWnd = $("#empWnd");
		empWnd.show();
		empWnd.dialog({
	    	title:'员工信息',
	        modal:true,
	        top:30,
			href : '${ctx}/business/toShowEmp.action',
	        buttons: [{
	        	text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					var row = $('#empList').datagrid('getSelected');
					if (!row){
						$.messager.alert('友情提示','请选择员工','info');
					}else{
						$('#baseName').textbox('setValue',row.user.name);
						$('#baseuId').val(row.uid);
						$('#baseempId').val(row.user.empId);
					}
					$('#empWnd').dialog('close');
				
				}
	        },{
	        	text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					$('#empWnd').dialog('close');
				} 
	        }]
	    });
    }
  </script>
</html>
